package com.css.fxfzdzzh.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.security.MessageDigest;

public class PlatformMd5Utils {
    public PlatformMd5Utils() {
    }

    public static String MD5Encode(String sourceString) {
        String resultString = null;

        try {
            resultString = new String(sourceString);
            MessageDigest var2 = MessageDigest.getInstance("MD5");
            resultString = byte2hexString(var2.digest(resultString.getBytes("UTF-8")));
        } catch (Exception var3) {
        }

        return resultString;
    }

    public static String MD5Encode(byte[] bytes) {
        String resultString = null;

        try {
            MessageDigest var2 = MessageDigest.getInstance("MD5");
            resultString = byte2hexString(var2.digest(bytes));
        } catch (Exception var3) {
        }

        return resultString;
    }

    public static String MD5Encode(String sourceString, boolean uppercase) {
        String result = MD5Encode(sourceString);
        return uppercase ? result.toUpperCase() : result;
    }

    public static String MD5Encode(byte[] bytes, boolean uppercase) {
        String result = MD5Encode(bytes);
        return uppercase ? result.toUpperCase() : result;
    }

    public static final String byte2hexString(byte[] bytes) {
        StringBuffer buf = new StringBuffer(bytes.length * 2);

        for(int i = 0; i < bytes.length; ++i) {
            if ((bytes[i] & 255) < 16) {
                buf.append("0");
            }

            buf.append(Long.toString((long)(bytes[i] & 255), 16));
        }

        return buf.toString();
    }

    public static String getMd5ByFile(File file) {
        String value = null;
        FileInputStream in = null;

        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            in = new FileInputStream(file);
            byte[] buffer = new byte[4096];
            boolean var5 = true;

            int length;
            while((length = in.read(buffer)) != -1) {
                md5.update(buffer, 0, length);
            }

            BigInteger var6 = new BigInteger(1, md5.digest());
            value = var6.toString(16);
        } catch (Exception var15) {
            var15.printStackTrace();
        } finally {
            try {
                in.close();
            } catch (IOException var14) {
            }

        }

        return value;
    }
}